/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.titama.control;


import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;


/**
 *
 * @author Thomas Müller
 * 
 */

public class AddCategoryController implements Initializable {
    
    DBConnect dbcon = new DBConnect();
    
    @FXML private Button AddButton;
    @FXML private TextField CategoryName;
   
    
    
    @Override
    public void initialize(URL url, ResourceBundle rb) 
    {
           
    }

    
    /**
     * 
     * Speichert die Kategorie in der Datenbank
     * 
     * @param e Ereignis
     */
    
    @FXML
    public void Save(ActionEvent e)
    {
        if(!CategoryName.getText().equals(""))
        {
            dbcon.addCategory(CategoryName.getText());
            Close(e);
            
        }
        else
        {
            CategoryName.setPromptText("Bitte geben Sie einen Namen ein..");
        }
    }
    
    /**
     * 
     * Schließt das Fenster
     * 
     * @param e Ereignis
     */
    
    @FXML
    public void Close(ActionEvent e)
    {
        Node  source = (Node)  e.getSource(); 
        Stage stage  = (Stage) source.getScene().getWindow();
        stage.close();       
    }
   
}
